package week06;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

abstract class Person{
	private String name;
	private int age;
	private boolean gender;
	
	public Person(){
		
	}
	
	
	
	public String getName() {
		return name;
	}



	public void setName(String name) {
		this.name = name;
	}



	public int getAge() {
		return age;
	}



	public void setAge(int age) {
		this.age = age;
	}



	public boolean isGender() {
		return gender;
	}



	public void setGender(boolean gender) {
		this.gender = gender;
	}



	public Person(String name, int age, boolean gender) {
		super();
		this.name = name;
		this.age = age;
		this.gender = gender;
	}
	public String toString(){
		return name + "-" + age + "-" + gender;
	}
	public boolean equals(Object obj){
		Person person = (Person)obj;
		if(this.name == null && person.name == null &&this.age == person.age &&this.gender == person.gender)
			return true;
		if(this.name.equals(person.name)&&this.age == person.age &&this.gender == person.gender)
			return true;
		else
			return false;
	}
}

class Student extends Person{
	private String stuNo;
	private String clazz;
	public Student(String name, int age, boolean gender,String stuNo, String clazz) {
		super(name,age,gender);
		this.stuNo = stuNo;
		this.clazz = clazz;
	}
	public Student(){
		
	}
	public String toString(){
		return "Student:"+super.toString() + "-" + stuNo + "-" + clazz;
	}
	public boolean equals(Object obj){
		Student stu = (Student) obj;
		if(super.equals((Person)stu)){
			if(this.stuNo.equals(stu.stuNo)&&this.clazz.equals(stu.clazz))
				return true;
			else if(this.stuNo == null && stu.stuNo == null){
				if((this.clazz == null && stu.clazz == null)||this.clazz.equals(stu.clazz))
					return true;}
			else if(this.clazz == null && stu.clazz == null){
				if((this.stuNo == null && stu.stuNo == null)||this.stuNo.equals(stu.stuNo))
					return true;}
		}
		return false;
	}
	
	
}


class Company{
	private String name;

	public Company(String name) {
		super();
		this.name = name;
	}
	
	public String toString(){
		return name;
	}
	
	public boolean equals(Object obj){
		Company com = (Company) obj;
		if(this.name == null && com.name ==null)
			return true;
		if(this.name.equals(com.name))
			return true;
		else
			return false;
	}
}

class Employee extends Person{
	private double salary;
	private Company company;
	
	
	
	public Employee() {
		super();
	}
	public Employee(String name, int age, boolean gender, double salary, Company company) {
		super(name,age,gender);
		this.salary = salary;
		this.company = company;
	}
	public String toString(){
		return "Employee:"+super.toString()+"-"+company+"-"+salary;
	}
	public boolean equals(Object obj){
		Person p = (Person)obj;
		Employee emp = (Employee)obj;
		if(super.equals(p)){
			if(this.company == null &&emp.company == null)
				return true;
			if(this.company.equals(emp.company)){
				DecimalFormat df1 = new DecimalFormat("#.#");
				DecimalFormat df2 = new DecimalFormat("#.#");
				if(df1.format(this.salary).equals(df2.format(emp.salary)))
					return true;}}
		return false;		
		
	}
}


public class Main4 {

	public static void main(String[] args) {
		Scanner sc =  new Scanner(System.in);
		Student student = new Student();
		Employee employee = new Employee();
		List<Person> personList = new ArrayList<Person>();
		while(sc.hasNextLine()){
			String str[] = sc.nextLine().split(" ");
			//System.out.println(str[0]+Integer.valueOf(str[2])+ Boolean.valueOf(str[3])+str[4]+str[5]);
			if(str[0].equals("s") ){
				student = new Student(str[1],Integer.valueOf(str[2]), Boolean.valueOf(str[3]),str[4], str[5]);
				personList.add(student);
			}
			else if(str[0].equals("e")){
				if(str[5].equals("null"))
					str[5] = null;
				employee = new Employee(str[1],Integer.valueOf(str[2]), Boolean.valueOf(str[3]),Double.valueOf(str[4]), new Company(str[5]));  
				personList.add(employee);
			}
			else
				break;
		}
		Comparator<Person> personcom = new Comparator<Person>() { 
			public int compare(Person p1, Person p2) { 
				if(p1.getName().compareTo(p2.getName()) != 0)
					return p1.getName().compareTo(p2.getName());
				else
					return (p1.getAge()-p2.getAge());
				} 
			};
			Collections.sort(personList, personcom);
			for(int i = 0; i < personList.size() ; i++)
				System.out.println(personList.get(i).toString());
			if(sc.next() == "exit"){
				sc.close();
				return ;
			}
			ArrayList<Student> stuList = new ArrayList<Student>();
			ArrayList<Employee> empList = new ArrayList<Employee>();
			for(Person person : personList){
				if(person instanceof Student && (!stuList.contains(person)))
					stuList.add((Student)person);
				if(person instanceof Employee && (!empList.contains(person)))
					empList.add((Employee)person);
			}
			System.out.println("stuList");
			for(Student stu : stuList)
				System.out.println(stu.toString());
			System.out.println("empList");
			for(Employee emp : empList)
				System.out.println(emp.toString());
			sc.close();
	}
}
	

